//file: ListIt.java
import java.io.*;
import java.util.*;

class ListIt {
	public static void main ( String args[] ) throws Exception
	{
		if(args.length == 0) {
			System.out.printf("Usage: ListIt <name>");
			return;
		}
		File file =  new File( args[0] );

		if ( !file.exists() || !file.canRead(  ) ) {
			System.out.println( file + " doesn't exist!" );
			System.out.println( "Creating the file " + file );
			try {
				FileWriter fw = new FileWriter ( file );
				PrintWriter pw = new PrintWriter( fw );
				pw.println( "File created by ListIt" );
				fw.close( );
			} catch (IOException e) {}
			return;
		}

		if ( file.isDirectory(  ) ) {
			String [] files = file.list();
			for (int i=0; i< files.length; i++)
				System.out.println( files[i] );
		}
		else {
			try {
				FileReader fr = new FileReader ( file );
				BufferedReader in = new BufferedReader( fr );
				String line;
				while ((line = in.readLine()) != null) {
					System.out.println(line);
				}
			}
			catch ( FileNotFoundException e ) {
				System.out.println( "File Disappeared" );
			}
		}
	}
}

